package cn.jzq.demo.web;

import cn.jzq.demo.entity.GeneralClass;
import cn.jzq.demo.entity.GeneralStudent;
import cn.jzq.demo.util.R;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/data")
@CrossOrigin
public class DataController {

    @GetMapping("/class")
    public R getClasses() {
        List<GeneralClass> classList = new ArrayList<>();
        GeneralClass clazz1 = new GeneralClass(1, "classOne");
        GeneralClass clazz2 = new GeneralClass(2, "classTwo");
        classList.add(clazz1);
        classList.add(clazz2);
        return R.ok(classList);
    }

    @GetMapping("/student/{classId}")
    public R getStudents(@PathVariable("classId") Integer classId) {
        List<GeneralStudent> list = new ArrayList<>();
        if (classId == 1) {
            GeneralStudent s1 = new GeneralStudent("1001", "jzq");
            GeneralStudent s2 = new GeneralStudent("1002", "mrx");
            list.add(s1);
            list.add(s2);
        } else {
            GeneralStudent s3 = new GeneralStudent("1003", "xxx");
            GeneralStudent s4 = new GeneralStudent("1004", "hello");
            list.add(s3);
            list.add(s4);
        }
        return R.ok(list);
    }
}
